<?php
/**
 * @file name : main.php
 * @package   :
 * @author    : Vo Thanh Minh
 * @email     : <thanhminhld@yahoo.com - thanhminhld@gmail.com>
 * @copyright : 2011
 *
 */
 if (!defined('BASEPATH')) {
    exit('No direct script access');
}

class Home extends Base_Controller
{
    /**
     * Home
     *
     * @author	: Vo Thanh Minh <thanhminhld@yahoo.com - thanhminhld@gmail.com>
     * @access	: public
     */
    public function Home()
    {
        parent::__construct();
    }
    /**
     * index
     *
     * @author	: Vo Thanh Minh <thanhminhld@yahoo.com - thanhminhld@gmail.com>
     * @access	: public
     */
    public function index()
    {
        $controlName = 'home';
        /**
         * San pham noi bat
         */
        $arrWhere = array('lang_id'       => $this->lang_default,
                          'product_show'  => 'Y',
                          'product_featured' => 'Y');
        $arrFeatured = $this->productspost_model->loadList($arrWhere, 'all', 0);
        /**
         * Tin kien truc
         */
        $arraNewsIndex = array();
        $arrOtherNews  = array();
        $arrNewsUrl    = 'news/';
        $arrWhere = array('lang_id'   => $this->lang_default,
                          'news_show' => 'Y');
        $arraNewsTmp = $this->newspost_model->loadList($arrWhere, 1, 0, 'news_id', 'DESC');
        if (count($arraNewsTmp) > 0) {
            $arraNewsIndex = $arraNewsTmp[0];
            $arrWhere = array('lang_id'     => $this->lang_default,
                              'category_id' => $arraNewsIndex->category_id,
                              'news_id !='  => $arraNewsIndex->news_id,
                              'news_show'   => 'Y');
            $arrOtherNews = $this->newspost_model->loadList($arrWhere, 3, 0, 'news_id', 'DESC');
        }
        /**
         * Tin tuc Tho Kim (Danh muc hien thi trang chu)
         */
        $arrWhere = array('lang_id'    => $this->lang_default,
                          'show_index' => 'Y');
        $newsCategoryIndex = array();
        $newsIndex         = array();
        $arrTmp = $this->news_model->loadList($arrWhere, 1, 0, 'category_id', 'DESC');
        if (count($arrTmp) > 0) {
            $newsCategoryIndex = $arrTmp[0];
            $arrWhere = array('lang_id'     => $this->lang_default,
                              'category_id' => $newsCategoryIndex->category_id,
                              'news_show'   => 'Y');
            $arrTmpNesIndex = $this->newspost_model->loadList($arrWhere, 1, 0, 'news_id', 'DESC');
            $newsIndex = $arrTmpNesIndex[0];
        }
        /**
         * Tu van (lay tin moi nhat cua menu tu van)
         */
        $arrWhere = array('lang_id'         => $this->lang_default,
                          'consultant_show' => 'Y');
        $arrTmp = $this->consultantpost_model->loadList($arrWhere, 1, 0, 'consultant_id', 'DESC');
        $arrConsultant = array();
        if (count($arrTmp) > 0) {
            $arrConsultant = $arrTmp[0];
        }
        /**
         * Tin bat dong san
         */
        $arrWhere = array('lang_id'   => $this->lang_default,
                          'news_show' => 'Y');
        $arrEstate = $this->newsestate_model->loadList($arrWhere, 8, 0, 'news_id', 'DESC');
        /**
         * Du an chao ban
         */
        $arrWhere = array('lang_id'   => $this->lang_default,
                          'news_show' => 'Y');
        $arrTmp = $this->saleproject_model->loadList($arrWhere, 1, 0, 'news_id', 'DESC');
        $arrSaleProj = array();
        if (count($arrTmp) > 0) {
            $arrSaleProj = $arrTmp[0];
        }
        /**
         * Read XML (xem ngay tot xau)
         */
        $this->load->library('rayFeedReader');
        $this->load->library('rayFeedWidget');
        $options = array('url' => 'http://feeds.feedburner.com/XemNgayTotXau-LichVanNien?format=xml',
                         'widget' => 'RayFeedWidget');
        $horoscopesHtml = $this->rayfeedreader->getInstance()->setOptions($options)->parse()->widget();
        $this->msmarty->assign('horoscopesHtml', $horoscopesHtml);
        $horoscopes =  $this->msmarty->fetch($controlName . '/horoscopes.tpl');
        $this->msmarty->assign('horoscopes', $horoscopes);

        $data = array('productFeatured' => $arrFeatured,
                      'productImgPath'  => 'application/uploads/productpost/',
                      'productPostUrl'  => 'products/products-detail/PP-',
                      'arrNews'         => $arraNewsIndex,
                      'arrNewsUrl'      => $arrNewsUrl,
                      'newsPostUrl'     => 'news/news-detail/NP-',
                      'arrOtherNews'    => $arrOtherNews,
                      'newsCategoryIndex' => $newsCategoryIndex,
                      'newsIndex'       => $newsIndex,
                      'arrConsultant'   => $arrConsultant,
                      'consultantPostUrl' => 'consultant/consultant-detail/CP-',
                      'arrEstate'       => $arrEstate,
                      'estatePostUrl'   => 'news/real-estate-detail/ES-',
                      'arrSaleProj'     => $arrSaleProj);

		$this->msmarty->assignArrVal($data);

        $homeFeatureProductSlide = $this->msmarty->fetch($controlName . '/feature_product_slide.tpl');
        $this->msmarty->assign('homeFeatureProductSlide', $homeFeatureProductSlide);



        $main = $this->msmarty->fetch($controlName . '/home.tpl');
        $this->msmarty->assign('main', $main);

        $realEstateNews = $this->msmarty->fetch($controlName . '/real_estate_news.tpl');
        $this->msmarty->assign('homeRealEstateNews', $realEstateNews);

        $this->msmarty->view();
    }
}